<!--
Copyright 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="../ct-commit-list.html">

<link rel="import" href="../../model/ct-commit-list-mock.html">

<script>
(function () {

var assert = chai.assert;

describe('ct-commit-list', function() {
  var list;

  beforeEach(function(done) {
    list = document.createElement('ct-commit-list');
    list.commitList = new CTCommitListMock();
    setTimeout(done);
  });

  function numOfMatchedSuspectedCommitInfo() {
    var html = list.shadowRoot.innerHTML;
    var results = html.match(/\d+ suspected CL\(s\)/g);
    return Object.size(results);
  }

  describe('commit list UI', function() {
    it('should show no commits by default', function() {
      var commits = list.shadowRoot.querySelectorAll('ct-commit');
      assert.lengthOf(commits, 0);
      assert.equal(numOfMatchedSuspectedCommitInfo(), 0);
    });

    describe('expanded test', function() {
      beforeEach(function(done) {
        list.commitList.repositories.first().expanded = true;
        setTimeout(done);
      });

      it('should show commit when expanded', function() {
        assert.lengthOf(list.shadowRoot.querySelectorAll('ct-commit'), 2);
        assert.equal(numOfMatchedSuspectedCommitInfo(), 0);
      });
    });
  });

  describe('summary of suspected commits', function() {
    it('should show up if they are in range', function(done) {
      list.suspectedCLsByRepo = {
        'blink': [
          {
            'commitPosition': 158544,
            'builds': ['https://abc']
          }
        ]
      };

      setTimeout(function() {
        assert.equal(numOfMatchedSuspectedCommitInfo(), 2);
        done();
      });
    });

    it('should not show up if they are out of range', function(done) {
      list.suspectedCLsByRepo = {
        'blink': [
          {
            'commitPosition': 258544,
            'builds': ['https://abc']
          }
        ]
      };

      setTimeout(function() {
        assert.equal(numOfMatchedSuspectedCommitInfo(), 0);
        done();
      });
    });
  });
});

})()
</script>
